<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('C5Game账户列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>后台管理sys_user的用户id：</label>
                            <input type="text" name="userId"/>
                        </li>
                        <li>
                            <label>c5的uid：</label>
                            <input type="text" name="uid"/>
                        </li>
                        <li>
                            <label>c5的app_key：</label>
                            <input type="text" name="appKey"/>
                        </li>
                        <li>
                            <label>c5的平台名称：</label>
                            <input type="text" name="c5Name"/>
                        </li>
                        <li>
                            <label>账户余额：</label>
                            <input type="text" name="balance"/>
                        </li>
                        <li>
                            <label>求购余额：</label>
                            <input type="text" name="buyBalance"/>
                        </li>
                        <li>
                            <label>steamId：</label>
                            <input type="text" name="steamId"/>
                        </li>
                        <li>
                            <label>steam头像：</label>
                            <input type="text" name="avatar"/>
                        </li>
                        <li>
                            <label>创建时间：</label>
                            <input type="text" class="time-input" placeholder="请选择创建时间" name="createDate"/>
                        </li>
                        <li>
                            <label>修改时间：</label>
                            <input type="text" class="time-input" placeholder="请选择修改时间" name="updateDate"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:account:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:account:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:account:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:account:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:account:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:account:remove')}]];
    var prefix = ctx + "system/account";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            refreshAccountInfoUrl: prefix + "/refreshAccountInfo",
            modalName: "C5Game账户",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '雪花id',
                    visible: false
                },
                {
                    field: 'userId',
                    title: '后台管理sys_user的用户id'
                },
                {
                    field: 'uid',
                    title: 'c5的uid'
                },
                {
                    field: 'appKey',
                    title: 'c5的app_key'
                },
                {
                    field: 'c5Name',
                    title: 'c5的平台名称'
                },
                {
                    field: 'balance',
                    title: '账户余额'
                },
                {
                    field: 'buyBalance',
                    title: '求购余额'
                },
                {
                    field: 'steamId',
                    title: 'steamId'
                },
                {
                    field: 'avatar',
                    title: 'steam头像'
                },
                {
                    field: 'status',
                    title: '状态 0:禁用 1:正常'
                },
                {
                    field: 'createDate',
                    title: '创建时间'
                },
                {
                    field: 'updateDate',
                    title: '修改时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.refreshAccountInfo(\'' + row.appKey + '\')"><i class="fa fa-remove"></i>刷新</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 修改原有的单个刷新函数，添加加载提示
    $.operate.refreshAccountInfo = function(appKey) {
        $.modal.loading("正在刷新账户信息...");
        $.ajax({
            type: 'POST',
            url: prefix + "/refreshAccountInfo",
            data: {
                appKey: appKey
            },
            success: function(result) {
                $.modal.closeLoading();
                if (result.code === 0) {
                    $.modal.msgSuccess("刷新成功");
                    $.table.refresh();
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function() {
                $.modal.closeLoading();
                $.modal.alertError("刷新失败");
            }
        });
    };

</script>
</body>
</html>